package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.ContainerGpuMap;
import com.accelstack.cmp.repository.ContainerGpuMapRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 容器GPU映射Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ContainerGpuMapService {
    
    private final ContainerGpuMapRepository containerGpuMapRepository;
    
    @Transactional
    public ContainerGpuMap create(ContainerGpuMap containerGpuMap) {
        return containerGpuMapRepository.save(containerGpuMap);
    }
    
    @Transactional
    public ContainerGpuMap update(ContainerGpuMap containerGpuMap) {
        return containerGpuMapRepository.save(containerGpuMap);
    }
    
    @Transactional
    public void deleteById(Long id) {
        containerGpuMapRepository.deleteById(id);
    }
    
    public Optional<ContainerGpuMap> findById(Long id) {
        return containerGpuMapRepository.findById(id);
    }
    
    public List<ContainerGpuMap> findAll() {
        return containerGpuMapRepository.findAll();
    }
    
    public Page<ContainerGpuMap> findAll(Pageable pageable) {
        return containerGpuMapRepository.findAll(pageable);
    }
    
    public List<ContainerGpuMap> findByContainerId(Long containerId) {
        return containerGpuMapRepository.findByContainerId(containerId);
    }
    
    public List<ContainerGpuMap> findByVirtualGpuId(Long virtualGpuId) {
        return containerGpuMapRepository.findByVirtualGpuId(virtualGpuId);
    }
}

